/**
 * Copyright (c) 2020-2021 浦东大爷 All rights reserved.
 * 机会永远都是留给有准备的人
 */
package com.job.moudle2.task3;

import java.math.BigDecimal;

/**
 * @author: gitwo
 * @date: 2020-11-15
 * @description:
 */
public class UserTest {

    public static void main(String[] args) {

        // 定义套餐
        TalkSetMeal talkSetMeal1 = new TalkSetMeal(2000, 1000, BigDecimal.valueOf(30.00));
        TalkSetMeal talkSetMeal2 = new TalkSetMeal(1000, 500, BigDecimal.valueOf(20.00));
        NetSetMeal netSetMeal1 = new NetSetMeal(30.00, BigDecimal.valueOf(15));
        NetSetMeal netSetMeal2 = new NetSetMeal(100.00, BigDecimal.valueOf(30));

        // 打印所有套餐信息
        showSetMeal(talkSetMeal1, talkSetMeal2, netSetMeal1, netSetMeal2);


        //小明去办了张手机卡
        SIMCard simCardXM = new SIMCard("xiaoming", "123456");
        simCardXM.setCardType(CardType.BIG);
        simCardXM.setCardNo("123456789"); // 以后可以增加一个随机生成定长字符串的函数
        simCardXM.setAccountBalance(BigDecimal.valueOf(100));//充值100元
        simCardXM.setNetData(netSetMeal1.getNetData());
        simCardXM.setTalkTimes(talkSetMeal1.getTalkTimes());
        simCardXM.show();
        simCardXM.preChargeBack(talkSetMeal1, netSetMeal1); //选择的套餐进行预扣费

        //小明打了个电话30分钟
        TalkServiceimpl talk = talkSetMeal1;
        talk.talk(30, simCardXM); //小明打了30分钟电话
        talk.talk(40, simCardXM); //小明又打了40分钟电话
        talk.talk(5, simCardXM); //小明又打了5分钟电话

        // 小明上了个网
        NetServiceImpl net = netSetMeal1;
        net.net(0.03, simCardXM); //小明打了30分钟电话
        net.net(1, simCardXM); //小明又打了40分钟电话
        net.net(0.43, simCardXM); //小明又打了5分钟电话

        // 联通爸爸后台看了下总共上网和通话时间有多少

        UserConsumption userConsumption = UserConsumption.getInstance();
        userConsumption.show();
    }

    /**
     * 父类引用引用子类对象的方式
     */
    public static void showSetMeal(SetMeal... setMeals) {
        for(SetMeal setMeal: setMeals) {
            setMeal.show();
        }
    }
}
